package com.itheima.sh.user.controller;

import com.itheima.sh.pojo.User;
import com.itheima.sh.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController{

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")                                       //添加Request对象
    public User queryById(@PathVariable("id") String username, HttpServletRequest request) {
        //获取网关gateway添加的请求头信息
        String name = request.getHeader("name");
        System.out.println("网关添加的请求头============================"+name);//hwl

        //System.out.println("================模拟异常");

        return userService.queryById(username);
    }
}
